import javax.swing.*;
import java.awt.event.*;



public class icsGUI extends JFrame implements ActionListener{
	private static JTextField textField;
	private static JTextField textField_1;
	private static JTextField textField_2;
	private static JTextField textField_3;
	private static final ButtonGroup buttonGroup = new ButtonGroup();
	private static JTextArea textArea;
	private static JRadioButton rdbtnPublic;
	private static JRadioButton rdbtnPrivate;
	
	//String variables that will be sent to error checking
	private String calClass = "";
	private String event = "";
	private String location = "";
	private String resources = "";
	private String comments = "";
	
	
	
	
	

	/**
	 * @param args
	 * Runs the GUI for the calendar project
	 */
	public static void main(String[] args) {
		icsGUI cal = new icsGUI();

		cal.setSize(440,740);
		cal.setTitle("ICS Calendar Project");
		
		cal.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		cal.getContentPane().setLayout(null);
		cal.setVisible(true);
		

		

	}
	
	
	/*
	 * GUI creation method
	 */
	public icsGUI(){
		
		JPanel panel = new JPanel();
		panel.setBounds(0, 0, 400, 678);
		this.getContentPane().add(panel);
		panel.setLayout(null);
		
		JLabel lblCreateCalendarFile = new JLabel("Create Calendar File");
		lblCreateCalendarFile.setBounds(137, 5, 125, 16);
		panel.add(lblCreateCalendarFile);
		
		//Event
		JLabel lblName = new JLabel("Event:");
		lblName.setBounds(23, 47, 61, 16);
		panel.add(lblName);
		textField = new JTextField();
		textField.setBounds(96, 41, 298, 28);
		panel.add(textField);
		textField.setColumns(10);
		//event action listener
		textField.addActionListener(this);
		
		//Radio buttons for public and private
		
		rdbtnPublic = new JRadioButton("Public");
		buttonGroup.add(rdbtnPublic);
		rdbtnPublic.setBounds(106, 70, 141, 23);
		panel.add(rdbtnPublic);
		rdbtnPublic.setSelected(true);
		rdbtnPrivate = new JRadioButton("Private");
		buttonGroup.add(rdbtnPrivate);
		rdbtnPrivate.setBounds(232, 70, 141, 23);
		panel.add(rdbtnPrivate);
		//event action listeners
		rdbtnPublic.addActionListener(this);
		rdbtnPrivate.addActionListener(this);
		
		//Location
		JLabel lblLocation = new JLabel("Location:");
		lblLocation.setBounds(23, 115, 61, 16);
		panel.add(lblLocation);
		textField_1 = new JTextField();
		textField_1.setBounds(96, 109, 298, 28);
		panel.add(textField_1);
		textField_1.setColumns(10);
		//event action listener
		textField_1.addActionListener(this);
		
		//Resources
		JLabel lblResources = new JLabel("Resources:");
		lblResources.setBounds(23, 170, 74, 16);
		panel.add(lblResources);
		textField_2 = new JTextField();
		textField_2.setBounds(96, 164, 298, 28);
		panel.add(textField_2);
		textField_2.setColumns(10);
		//event action listener
		textField_2.addActionListener(this);
		
		//Comments
		JLabel lblComments = new JLabel("Comments:");
		lblComments.setBounds(23, 235, 74, 16);
		panel.add(lblComments);
		textField_3 = new JTextField();
		textField_3.setBounds(96, 229, 298, 28);
		panel.add(textField_3);
		textField_3.setColumns(10);
		//event action listener
		textField_3.addActionListener(this);
		
		//Start date/time
		JLabel lblStart = new JLabel("Start:");
		lblStart.setBounds(23, 295, 61, 16);
		panel.add(lblStart);
		JLabel lblDatetime = new JLabel("Date/Time");
		lblDatetime.setBounds(23, 313, 74, 16);
		panel.add(lblDatetime);
		//Date/Time start mo
		JComboBox comboBox = new JComboBox();
		comboBox.setModel(new DefaultComboBoxModel(new String[] {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}));
		comboBox.setBounds(96, 291, 131, 27);
		panel.add(comboBox);		
		//Date/Time start day
		JComboBox comboBox_1 = new JComboBox();
		comboBox_1.setModel(new DefaultComboBoxModel(new String[] {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"}));
		comboBox_1.setBounds(232, 291, 61, 27);
		panel.add(comboBox_1);
		//Date/Time start yr
		JComboBox comboBox_2 = new JComboBox();
		comboBox_2.setModel(new DefaultComboBoxModel(new String[] {"2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020", "2021", "2022", "2023", "2024", "2025", "2026"}));
		comboBox_2.setBounds(305, 291, 89, 27);
		panel.add(comboBox_2);
		//Date/Time start hr
		JComboBox comboBox_3 = new JComboBox();
		comboBox_3.setModel(new DefaultComboBoxModel(new String[] {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22","23"}));
		comboBox_3.setBounds(153, 320, 74, 27);
		panel.add(comboBox_3);
		//Date/Time start min
		JComboBox comboBox_4 = new JComboBox();
		comboBox_4.setModel(new DefaultComboBoxModel(new String[] {"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59"}));
		comboBox_4.setBounds(232, 320, 74, 27);
		panel.add(comboBox_4);
		//Date/Time start am pm
		/*JComboBox comboBox_10 = new JComboBox();
		comboBox_10.setModel(new DefaultComboBoxModel(new String[] {"am", "pm"}));
		comboBox_10.setBounds(315, 320, 79, 27);
		panel.add(comboBox_10);*/
		
		//action listeners
		comboBox.addActionListener(this);
		comboBox_1.addActionListener(this);
		comboBox_2.addActionListener(this);
		comboBox_3.addActionListener(this);
		comboBox_4.addActionListener(this);
		
		
		
		
		//End date/time
		JLabel lblEnd = new JLabel("End:");
		lblEnd.setBounds(23, 381, 61, 16);
		panel.add(lblEnd);		
		JLabel lblDatetime_1 = new JLabel("Date/Time");
		lblDatetime_1.setBounds(23, 399, 74, 16);
		panel.add(lblDatetime_1);
		//Date/Time end mo
		JComboBox comboBox_5 = new JComboBox();
		comboBox_5.setModel(new DefaultComboBoxModel(new String[] {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}));
		comboBox_5.setBounds(96, 388, 131, 27);
		panel.add(comboBox_5);
		//Date/Time end day
		JComboBox comboBox_6 = new JComboBox();
		comboBox_6.setModel(new DefaultComboBoxModel(new String[] {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"}));
		comboBox_6.setBounds(232, 388, 61, 27);
		panel.add(comboBox_6);
		//Date/Time end yr
		JComboBox comboBox_7 = new JComboBox();
		comboBox_7.setModel(new DefaultComboBoxModel(new String[] {"2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020", "2021", "2022", "2023", "2024", "2025", "2026"}));
		comboBox_7.setBounds(305, 388, 89, 27);
		panel.add(comboBox_7);
		//Date/Time end hr
		JComboBox comboBox_8 = new JComboBox();
		comboBox_8.setModel(new DefaultComboBoxModel(new String[] {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12","13","14","15","16","17","18","19","20","21","22","23"}));
		comboBox_8.setBounds(153, 417, 74, 27);
		panel.add(comboBox_8);
		//Date/Time end min
		JComboBox comboBox_9 = new JComboBox();
		comboBox_9.setModel(new DefaultComboBoxModel(new String[] {"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59"}));
		comboBox_9.setBounds(232, 417, 74, 27);
		panel.add(comboBox_9);
		//Date/Time end am pm
		/*JComboBox comboBox_11 = new JComboBox();
		comboBox_11.setModel(new DefaultComboBoxModel(new String[] {"am", "pm"}));
		comboBox_11.setBounds(315, 417, 79, 27);
		panel.add(comboBox_11);*/
		
		//action listeners
		comboBox_5.addActionListener(this);
		comboBox_6.addActionListener(this);
		comboBox_7.addActionListener(this);
		comboBox_8.addActionListener(this);
		comboBox_9.addActionListener(this);
		
		
		
		//Description 
		JLabel lblDescription = new JLabel("Description:");
		lblDescription.setBounds(23, 488, 84, 16);
		panel.add(lblDescription);
		textArea = new JTextArea();
		textArea.setBounds(106, 488, 276, 143);
		panel.add(textArea);
		
		//Generate file button
		JButton btnGenerateFile = new JButton("Generate File");
		btnGenerateFile.setBounds(137, 643, 117, 29);
		panel.add(btnGenerateFile);
		//event action listener
		btnGenerateFile.addActionListener(this);
		
		
		
		
	}


	@Override
	public void actionPerformed(ActionEvent ae) {

		if(ae.getSource() instanceof JTextField){
			
			//capture the text in a string variable
			if(ae.getSource() == textField){
				event = textField.getText();
			}
			else if(ae.getSource() == textField_1){
				location = textField_1.getText();
				
			}
			else if(ae.getSource() == textField_1){
				resources = textField_2.getText();
				
			}
			else if(ae.getSource() == textField_1){
				comments = textField_3.getText();
	
			}
		}
		
		else if(ae.getSource() instanceof JRadioButton){
			if(rdbtnPublic.isSelected()){	
				calClass = "PUBLIC";
				
			}
			else if(rdbtnPrivate.isSelected()){
				calClass = "PRIVATE";
				
			}	
		}
		
		else if(ae.getSource() instanceof JComboBox){
			
			//figure out which combo box was changed, save info to String
			
		}
		
		else if(ae.getSource() instanceof JButton){
			
			//check for all of the variables, then format and give user .ics file
			
		}
		
	}
	
	
	//getter methods
	public String getEventName(){
		
		return event;
	}
	
	public String getCalClass(){

		return calClass;
	}
	
	public String getCalLocation(){
		
		return location;
	}
	
	public String getCalResources(){
		
		return resources;
	}
	
	public String getCalComments()
	{
		return comments;
	}

	
	
	
}
